<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增活动</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
</head>
<style>
    .layui-input-block {
        margin-left: 130px !important;
    }

    .layui-form-label {
        width: auto;
    }
</style>
<body style="height: 750px;background-color: white">
<div style="width:80%;margin:15px auto;text-align: center" class="layui-btn-group" id="btngroup">
    <button type="button" id="btnchina" class="layui-btn layui-btn-primary" onclick="clickbtn(0)">中文</button>
    <button type="button" id="btnenglish" class="layui-btn layui-btn-primary" onclick="clickbtn(1)">英语</button>
    <!--    泰语-->
    <button type="button" id="btnlaowo" class="layui-btn" onclick="clickbtn(2)">泰语</button>
    <button type="button" id="btnjianpuzhai" class="layui-btn layui-btn-primary" onclick="clickbtn(3)">柬埔寨</button>
</div>
<div style="width:80%;height:100%;margin:15px auto;">
    <form class="layui-form" action="">
        <div class="layui-form-item" id="title_div" style="display: none">
            <label class="layui-form-label">区域名称：</label>
            <div class="layui-input-block">
                <input type="text" name="areaName" id="areaName" placeholder="请输入区域名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="title_en_div" style="display: none">
            <label class="layui-form-label">区域名称英文：</label>
            <div class="layui-input-block">
                <input type="text" name="areaName_en" id="areaName_en" placeholder="请输入区域名称英文" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="title_tai_div">
            <label class="layui-form-label">区域名称泰文：</label>
            <div class="layui-input-block">
                <input type="text" name="areaName_tai" id="areaName_tai" required lay-verify="required" placeholder="请输入区域名称泰文"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="title_kh_div" style="display: none">
            <label class="layui-form-label">柬埔寨名称：</label>
            <div class="layui-input-block">
                <input type="text" name="areaName_kh" id="areaName_kh" placeholder="请输入区域名称柬埔寨语" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" id="discribe_div" >
            <label class="layui-form-label">区域简述：</label>
            <div class="layui-input-block">
                <input type="text" name="areaDescribe" id="areaDescribe" placeholder="请输入区域简述" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item" style="margin-top: 20px;margin: auto">
            <div class="layui-input-block">
                <button class="layui-btn" id="addWuye" lay-submit lay-filter="addWuye">立即添加</button>
            </div>
        </div>
    </form>
</div>
</body>
<script src="/js/layui/layui.js"></script>
<script src="/js/layui/layui.all.js"></script>
<script src="/admin/js/token.js"></script>
</html>
<script>
    var $ = layui.$;
    var layedit = layui.layedit;
    var form = layui.form;

    //添加操作
    form.on('submit(addWuye)', function (data) {
        var areaName = $("#areaName").val();
        var areaName_en = $("#areaName_en").val();
        var areaName_tai = $("#areaName_tai").val();
        var areaName_kh = $("#areaName_kh").val();
        var areaDescribe = $("#areaDescribe").val();

        if (areaName==null || areaName==""){
            layer.msg("请填写中文的区域名称");
        }else if (areaName_en==null || areaName_tai==""){
            layer.msg("请填写英文的区域名称");
        }else if (areaName_tai==null || areaName_tai==""){
            layer.msg("请填写泰语的区域名称");
        }else if (areaDescribe==null || areaDescribe==""){
            layer.msg("请填写区域描述");
        }else if (areaName_kh==null || areaName_kh==""){
            layer.msg("请填写柬埔寨语言区域名称");
        } else{
            data.field.areaName= areaName;
            data.field.areaName_en=areaName_en;
            data.field.areaName_tai=areaName_tai;
            data.field.areaDescribe=areaDescribe;
            var msgMovie = layer.load(1);
            $.ajax({
                url: "/area/addArea",
                type: "post",
                contentType: 'application/json',
                data:JSON.stringify(data.field),
                success: function (data) {
                    if (data.code == 200) {
                        $("#addWuye").prop("disabled", true);
                        $("#addWuye").attr("class", "layui-btn layui-btn-disabled");
                        layer.close(layer.index);
                        layer.msg('添加成功');
                        setTimeout(function () {
                            window.location.reload();
                        }, 2000);
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error: function () {
                    console.log("ajax error");
                }
            });
            layer.close(msgMovie);
        }

        return false;
    });

    function clickbtn(index) {
        var btns = $("#btngroup").find("button");
        if (index == 0) {
            $("#title_div").css("display", "block");
            $("#title_en_div").css("display", "none");
            $("#title_tai_div").css("display", "none");
            $("#title_kh_div").css("display","none");
        } else if (index == 1) {
            $("#title_div").css("display", "none");
            $("#title_en_div").css("display", "block");
            $("#title_tai_div").css("display", "none");
            $("#title_kh_div").css("display","none");
        } else if (index == 2) {
            $("#title_div").css("display", "none");
            $("#title_en_div").css("display", "none");
            $("#title_tai_div").css("display", "block");
            $("#title_kh_div").css("display","none");
        } else if (index == 3) {
            $("#title_div").css("display", "none");
            $("#title_en_div").css("display", "none");
            $("#title_tai_div").css("display", "none");
            $("#title_kh_div").css("display","block");
        }
        for (let i = 0; i < btns.length; i++) {
            if (i == index) {
                btns[i].setAttribute("class", "layui-btn");
                continue;
            }
            btns[i].setAttribute("class", "layui-btn layui-btn-primary");
        }
    }
</script>
</html>